/* 
 * Copyright [2018] [Alex/libo(liboms@hotmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.apidoc.model;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.List;

/** 
 * @title ApiDefination.java  
 * @package com.hyts.apidoc.model  
 * @description API文档单个接口的定义规则服务可以作为单个类中的单个接口定义类的方法  
 * @see {@link ApiParam} 参数信息类
 * @author libo/Alex
 * @email liboms@hotmail.com/liboware@163.com  
 * @date 2018年4月18日 
 * @version V1.0 
 */
public final class ApiDefination {
	
	/**  
	 * <p>包名称信息</p> 
	 * @fieldName packageName
	 * @fieldType String
	 */ 
	private String packageName;
	
	/**  
	 * <p>api方法接口方法名称rest服务请求接口明</p> 
	 * @fieldName name
	 * @fieldType String
	 */ 
	private String name;
	
	/**  
	 * <p>api方法描述信息</p> 
	 * @fieldName description
	 * @fieldType String
	 */ 
	private String description;
	
	/**  
	 * <p>请求地址URL</p> 
	 * @fieldName requestUrl
	 * @fieldType String
	 */ 
	private String requestUrl;
	
	/**  
	 * <p>请求参数列表</p> 
	 * @fieldName request
	 * @fieldType List<ApiParam>
	 */ 
	private List<ApiParam> inputParameters;
	
	/**  
	 * <p>结果参数列表</p> 
	 * @fieldName outputParameters
	 * @fieldType List<ApiParam>
	 */ 
	private List<ApiParam> outputParameters;

	/**
	 * <p>捕获异常列表</p>
	 * @fieldName outputParameters
	 * @fieldType List<ApiParam>
	 */
	private List<String> exceptionList;

	/**  
	 * @name name's getter method
	 * @param none
	 * @return name
	 */
	public String getName() {
		if (outputParameters != null) {
			int index =  outputParameters.get(0).getParamName().lastIndexOf(".")+1;
			return outputParameters.get(0).getParamName().substring(index);
		}
		return "";
	}

	/**  
	 * @name name's setter method
	 * @param name
	 * @return void
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**  
	 * @name description's getter method
	 * @param none
	 * @return description
	 */
	public String getDescription() {
		return description;
	}

	/**  
	 * @name description's setter method
	 * @param description
	 * @return void
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**  
	 * @name requestUrl's getter method
	 * @param none
	 * @return requestUrl
	 */
	public String getRequestUrl() {
		return requestUrl;
	}

	/**  
	 * @name requestUrl's setter method
	 * @param requestUrl
	 * @return void
	 */
	public void setRequestUrl(String requestUrl) {
		this.requestUrl = requestUrl;
	}

	/**  
	 * @name inputParameters's getter method
	 * @param none
	 * @return inputParameters
	 */
	public List<ApiParam> getInputParameters() {
		return inputParameters;
	}

	public String getInputParametersText(){
		//輸入參數
		return JSONArray.toJSONString(inputParameters);
	}

	/**
	 * @name inputParameters's setter method
	 * @param inputParameters
	 * @return void
	 */
	public void setInputParameters(List<ApiParam> inputParameters) {
		this.inputParameters = inputParameters;
	}



	/**  
	 * @name outputParameters's getter method
	 * @param none
	 * @return outputParameters
	 */
	public List<ApiParam> getOutputParameters() {
		return outputParameters;
	}


	public String getOutputParametersText(){
		/*JSONArray jsonArray = new JSONArray();
		if(inputParameters != null){
			inputParameters.parallelStream().forEach(param->{
				JSONObject jsonObject = new JSONObject();
				jsonObject.put("paramType",param.getParamType());
				jsonArray.add(jsonObject);
			});
		}*/
		if(outputParameters != null) {
			return JSONObject.toJSONString(outputParameters.get(0).getParamType());
		}
		return new JSONObject().toJSONString();
	}

	/**  
	 * @name outputParameters's setter method
	 * @param outputParameters
	 * @return void
	 */
	public void setOutputParameters(List<ApiParam> outputParameters) {
		this.outputParameters = outputParameters;
	}

	/**  
	 * @name packageName's getter method
	 * @param none
	 * @return packageName
	 */
	public String getPackageName() {
		return packageName;
	}

	/**  
	 * @name packageName's setter method
	 * @param packageName
	 * @return void
	 */
	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}

	public List<String> getExceptionList() {
		return exceptionList;
	}

	public void setExceptionList(List<String> exceptionList) {
		this.exceptionList = exceptionList;
	}
}
